const mysql = require('mysql2');

const getDB = () => {
    try {
        // 创建一个数据库连接
        const connection = mysql.createConnection({
            host: 'localhost',
            user: 'root',
            database: 'upload_file',
            password: '123456789',
            waitForConnections: false,
            connectionLimit: 10,
            queueLimit: 0
        });

        // 开启连接
        connection.connect(
            () => {
            console.log('连接成功');
            }
        );

        return {
            find: () => {
                return connection.promise();
            },
            close: () => {
                connection.end(
                    () => {
                        console.log('释放连接');
                    }
                )
            }
        }
    }
    catch (error) {
        console.log('error', error);
    }
};

module.exports  = {
    getDB
};